<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Combined sizing of drivers, repeaters, and wire</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/circuit_design/html/wire_driver_sizing.html">
<link rel="stylesheet" href="../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Combined sizing of drivers, repeaters, and wire</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#plots">Plots</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Section 5.2,  L. Vandenberghe, S. Boyd, and A. El Gamal</span>
<span class="comment">% "Optimizing dominant time constant in RC circuits"</span>
<span class="comment">% Original by Lieven Vandenberghe</span>
<span class="comment">% Adapted for CVX by Joelle Skaf - 11/25/05</span>
<span class="comment">% Modified by Michael Grant - 3/8/06</span>
<span class="comment">%</span>
<span class="comment">% The first driver drives an interconnect wire, modeled as n RC Pi segments</span>
<span class="comment">% connected to a repeater, which drives a capacitive load through another n</span>
<span class="comment">% segment wires. The problem is to determine the sizes of the wire segments</span>
<span class="comment">% (x1, . . . , x40) and the sizes of the driver &amp; repeater d1 and d2.</span>
<span class="comment">% We want to minimize area subject to bound on the combined delay Tdom1 +</span>
<span class="comment">% Tdom2 of the two stages.</span>
<span class="comment">%               minimize        L(d1 + d2) + sum(xi*li)</span>
<span class="comment">%                   s.t.        0 &lt;= xi &lt;= wmax</span>
<span class="comment">%                               d1 &gt;=0 , d2 &gt;= 0</span>
<span class="comment">%                               (Tmax/2)G1(x, d1, d2) - C1(x,d2) &gt;= 0</span>
<span class="comment">%                               (Tmax/2)G2(x, d1, d2) - C2(x) &gt;= 0</span>

<span class="comment">%</span>
<span class="comment">% Circuit parameters</span>
<span class="comment">%</span>

n = 21;        <span class="comment">% number of nodes per wire</span>
m = n-1;       <span class="comment">% number of segments per wire</span>
g = 1.0;       <span class="comment">% output conductance is g times driver size</span>
c0 = 1.0;      <span class="comment">% input capacitance of driver is co + c*driver size</span>
c = 3.0;
alpha = 10;    <span class="comment">% wire segment: two capacitances beta*width</span>
beta = 0.5;    <span class="comment">% wire segment: conductance alpha*width</span>
C = 50;        <span class="comment">% external load</span>
L = 10.0;      <span class="comment">% area is sum xi + L*(d1+d2)</span>
wmax = 2.0;    <span class="comment">% maximum wire width</span>
dmax = 100.0;  <span class="comment">% maximum driver size</span>

<span class="comment">%</span>
<span class="comment">% Construct the capacitance and conductance matrices</span>
<span class="comment">%   C1(x) = C10 + w11 * C11 + w21 * C12 + ...</span>
<span class="comment">%   C2(x) = C20 + w11 * C21 + w21 * C22 + ...</span>
<span class="comment">%   G1(x) = G10 + w11 * G11 + w21 * G12 + ...</span>
<span class="comment">%   G2(x) = G20 + w11 * G21 + w21 * G22 + ...</span>
<span class="comment">% and we assemble the coefficient matrices together as follows:</span>
<span class="comment">%   CC = [ C10(:) C11(:) C12(:) ... ; C20(:) C21(:) C22(:) ... ]</span>
<span class="comment">%   GG = [ G10(:) G11(:) G12(:) ... ; C20(:) C21(:) C22(:) ... ]</span>
<span class="comment">%</span>
<span class="comment">%</span>

CC = zeros(n,n,2,2*m+3);
GG = zeros(n,n,2,2*m+3);
<span class="comment">% load on first circuit from second driver = c0 + c * d2</span>
CC(n,n,1,1    ) = c0;
CC(n,n,1,2*m+3) = c;
<span class="comment">% external load</span>
CC(n,n,2,1) = C;
<span class="comment">% output conductances of drivers</span>
GG(1,1,1,2*m+2) = g;
GG(1,1,2,2*m+3) = g;
<span class="comment">% segment capacitances and conductances</span>
<span class="keyword">for</span> i = 1 : n-1,
    CC(i:i+1,i:i+1,1,  i+1) =  beta * [1, 0; 0,1];
    CC(i:i+1,i:i+1,2,m+i+1) =  beta * [1, 0; 0,1];
    GG(i:i+1,i:i+1,1,  i+1) = alpha * [1,-1;-1,1];
    GG(i:i+1,i:i+1,2,m+i+1) = alpha * [1,-1;-1,1];
<span class="keyword">end</span>
<span class="comment">% reshape for Matlab use</span>
CC = reshape( CC, n*n*2, 2*m+3 );
GG = reshape( GG, n*n*2, 2*m+3 );

<span class="comment">%</span>
<span class="comment">% Compute points the tradeoff curve and the sample solution</span>
<span class="comment">%</span>

npts    = 50;
delays  = linspace( 150, 500, npts );
xdelays = 189;
xnpts   = length( xdelays );
areas   = zeros( 1, npts );
xareas  = zeros( 1, xnpts );
<span class="keyword">for</span> i = 1 : npts + xnpts,

    <span class="keyword">if</span> i &gt; npts,
        xi = i - npts;
        delay = xdelays(xi);
        disp( sprintf( <span class="string">'Particular solution %d of %d (Tmax = %g)'</span>, xi, xnpts, delay ) );
    <span class="keyword">else</span>,
        delay = delays(i);
        disp( sprintf( <span class="string">'Point %d of %d on the tradeoff curve (Tmax = %g)'</span>, i, npts, delay ) );
    <span class="keyword">end</span>

    <span class="comment">%</span>
    <span class="comment">% Construct and solve the convex model</span>
    <span class="comment">%</span>

    cvx_begin <span class="string">sdp</span> <span class="string">quiet</span>
        variables <span class="string">w(m,2)</span> <span class="string">d(1,2)</span>
        variable <span class="string">G(n,n,2)</span> <span class="string">symmetric</span>
        variable <span class="string">C(n,n,2)</span> <span class="string">symmetric</span>
        minimize( L * sum(d) + sum(w(:)) );
        G == reshape( GG * [ 1 ; w(:) ; d(:) ], n, n, 2 );
        C == reshape( CC * [ 1 ; w(:) ; d(:) ], n, n, 2 );
        <span class="comment">% This is actually two LMIs, one for each circuit</span>
        (delay/2) * G - C &gt;= 0;
        0 &lt;= w(:) &lt;= wmax;
        d(:) &gt;= 0;
    cvx_end

    <span class="keyword">if</span> i &lt;= npts,
        areas(i) = cvx_optval;
    <span class="keyword">else</span>
        xareas(xi) = cvx_optval;

        <span class="comment">%</span>
        <span class="comment">% Draw solution, plotting drivers as a block with width os</span>
        <span class="comment">% and height L/(2*os).</span>
        <span class="comment">%</span>

        figure(2*xi);
        os = 3;
        m2 = 2 * m;
        ss = max( L * max( d ) / os, max( w(:) ) );
        x  = reshape( [ 1 : m ; 1 : m ], 1, m2 );
        y  = 0.5 * [ - w(x,:) ; w(x(end:-1:1),:) ; + w(1,:) ];
        yd = ( 0.5 * L / os ) * [ -d ; -d ; +d ; +d ; -d ];
        x   = reshape( [ 0 : m - 1 ; 1 : m ], m2, 1 );
        x   = [ x ; x(end:-1:1,:) ; 0 ];
        xd  = [ 0 ; os ; os ; 0 ; 0 ];
        x   = x + os + 0.5;
        xd  = [ xd, xd + os + m + 1 ];
        x   = [ x, x + os + m + 1 ];
        fill( x, y, 0.9 * ones(size(y)), xd, yd, 0.9 * ones(size(yd)) );
        hold <span class="string">on</span>
        plot( x, y, <span class="string">'-'</span>, xd, yd, <span class="string">'-'</span> );
        axis( [-0.5, 2*m+2*os+2, -0.5*ss-0.1,0.5*ss+0.1 ] );
        set( gca, <span class="string">'XTick'</span>, [x(1,1),x(1,1)+m,x(1,2),x(1,2)+m] );
        set( gca, <span class="string">'XTicklabel'</span>, {<span class="string">'0'</span>,num2str(m),<span class="string">'0'</span>,num2str(m)} );
        colormap(gray);
        caxis([-1,1])
        title(sprintf(<span class="string">'Sample solution (%d), Tmax = %g'</span>, xi, delay ));

        <span class="comment">%</span>
        <span class="comment">% Build the state space models and plot step responses</span>
        <span class="comment">%</span>

        figure(2*xi+1);
        T = linspace(0,1000,1000);
        tdom = []; telm = []; tthresh = []; Y = {};
        <span class="keyword">for</span> k = 1 : 2,
            A = -inv(C(:,:,k))*G(:,:,k);
            B = -A* ones(n,1);
            tdom(k) = max(eig(inv(G(:,:,k))*C(:,:,k)));
            telm(k) = max(sum((inv(G(:,:,k))*C(:,:,k))'));
            Y{k} = simple_step(A,B,T(2),length(T));
            Y{k} = Y{k}(n,:);
            tthresh(k) = min(find(Y{k}&gt;=0.5));
        <span class="keyword">end</span>
        plot( T, Y{1}, <span class="string">'-'</span>, T, Y{2}, <span class="string">'-'</span> );
        axis([0 T(500) 0 1]);
        xlabel(<span class="string">'time'</span>);
        ylabel(<span class="string">'v'</span>);
        hold <span class="string">on</span>;
        text(tdom(1),0,<span class="string">'d1'</span>);
        text(telm(2),0,<span class="string">'e1'</span>);
        text(tthresh(1),0,<span class="string">'t1'</span>);
        text(tdom(1)+tdom(2),0,<span class="string">'d2'</span>);
        text(tdom(1)+telm(2),0,<span class="string">'e2'</span>);
        text(tdom(1)+tthresh(2),0,<span class="string">'t2'</span>);
        plot(tdom(1)*[1;1],[0;1],<span class="string">'--'</span>);
        plot(telm(1)*[1;1],[0;1],<span class="string">'--'</span>);
        plot(tthresh(1)*[1;1],[0;1],<span class="string">'--'</span>);
        plot((tdom(1)+tdom(2))*[1;1],[0;1],<span class="string">'--'</span>);
        plot((tdom(1)+telm(2))*[1;1],[0;1],<span class="string">'--'</span>);
        plot((tdom(1)+tthresh(2))*[1;1],[0;1],<span class="string">'--'</span>);
        title(sprintf(<span class="string">'Step responses for sample solution (%d), Tmax = %g'</span>, xi, delay ));

     <span class="keyword">end</span>

<span class="keyword">end</span>

<span class="comment">%</span>
<span class="comment">% Plot tradeoff curve</span>
<span class="comment">%</span>

figure(1)
ind = isfinite(areas);
plot(areas(ind), delays(ind));
xlabel(<span class="string">'Area'</span>);
ylabel(<span class="string">'Tdom'</span>);
title(<span class="string">'Area-delay tradeoff curve'</span>);
hold <span class="string">on</span>
<span class="keyword">for</span> k = 1 : xnpts,
    text( xareas(k), xdelays(k), sprintf( <span class="string">'(%d)'</span>, k ) );
<span class="keyword">end</span>
</pre>
<a id="output"></a>
<pre class="codeoutput">
Point 1 of 50 on the tradeoff curve (Tmax = 150)
Point 2 of 50 on the tradeoff curve (Tmax = 157.143)
Point 3 of 50 on the tradeoff curve (Tmax = 164.286)
Point 4 of 50 on the tradeoff curve (Tmax = 171.429)
Point 5 of 50 on the tradeoff curve (Tmax = 178.571)
Point 6 of 50 on the tradeoff curve (Tmax = 185.714)
Point 7 of 50 on the tradeoff curve (Tmax = 192.857)
Point 8 of 50 on the tradeoff curve (Tmax = 200)
Point 9 of 50 on the tradeoff curve (Tmax = 207.143)
Point 10 of 50 on the tradeoff curve (Tmax = 214.286)
Point 11 of 50 on the tradeoff curve (Tmax = 221.429)
Point 12 of 50 on the tradeoff curve (Tmax = 228.571)
Point 13 of 50 on the tradeoff curve (Tmax = 235.714)
Point 14 of 50 on the tradeoff curve (Tmax = 242.857)
Point 15 of 50 on the tradeoff curve (Tmax = 250)
Point 16 of 50 on the tradeoff curve (Tmax = 257.143)
Point 17 of 50 on the tradeoff curve (Tmax = 264.286)
Point 18 of 50 on the tradeoff curve (Tmax = 271.429)
Point 19 of 50 on the tradeoff curve (Tmax = 278.571)
Point 20 of 50 on the tradeoff curve (Tmax = 285.714)
Point 21 of 50 on the tradeoff curve (Tmax = 292.857)
Point 22 of 50 on the tradeoff curve (Tmax = 300)
Point 23 of 50 on the tradeoff curve (Tmax = 307.143)
Point 24 of 50 on the tradeoff curve (Tmax = 314.286)
Point 25 of 50 on the tradeoff curve (Tmax = 321.429)
Point 26 of 50 on the tradeoff curve (Tmax = 328.571)
Point 27 of 50 on the tradeoff curve (Tmax = 335.714)
Point 28 of 50 on the tradeoff curve (Tmax = 342.857)
Point 29 of 50 on the tradeoff curve (Tmax = 350)
Point 30 of 50 on the tradeoff curve (Tmax = 357.143)
Point 31 of 50 on the tradeoff curve (Tmax = 364.286)
Point 32 of 50 on the tradeoff curve (Tmax = 371.429)
Point 33 of 50 on the tradeoff curve (Tmax = 378.571)
Point 34 of 50 on the tradeoff curve (Tmax = 385.714)
Point 35 of 50 on the tradeoff curve (Tmax = 392.857)
Point 36 of 50 on the tradeoff curve (Tmax = 400)
Point 37 of 50 on the tradeoff curve (Tmax = 407.143)
Point 38 of 50 on the tradeoff curve (Tmax = 414.286)
Point 39 of 50 on the tradeoff curve (Tmax = 421.429)
Point 40 of 50 on the tradeoff curve (Tmax = 428.571)
Point 41 of 50 on the tradeoff curve (Tmax = 435.714)
Point 42 of 50 on the tradeoff curve (Tmax = 442.857)
Point 43 of 50 on the tradeoff curve (Tmax = 450)
Point 44 of 50 on the tradeoff curve (Tmax = 457.143)
Point 45 of 50 on the tradeoff curve (Tmax = 464.286)
Point 46 of 50 on the tradeoff curve (Tmax = 471.429)
Point 47 of 50 on the tradeoff curve (Tmax = 478.571)
Point 48 of 50 on the tradeoff curve (Tmax = 485.714)
Point 49 of 50 on the tradeoff curve (Tmax = 492.857)
Point 50 of 50 on the tradeoff curve (Tmax = 500)
Particular solution 1 of 1 (Tmax = 189)
</pre>
<a id="plots"></a>
<div id="plotoutput">
<img src="wire_driver_sizing__01.png" alt=""> <img src="wire_driver_sizing__02.png" alt=""> <img src="wire_driver_sizing__03.png" alt=""> 
</div>
</div>
</body>
</html>